import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
testCase = "DBshop013_添加编辑商品分类"

# 实例化浏览器对象 打开指定网站
driver = openBrowser(urlAdmin)
# 后台登录
DBshopLoginAdmin(driver)
# 处理三级菜单
DBshopEnterMenu3(driver,"商品管理","管理分类","商品分类")
# 点击添加
driver.find_element_by_xpath("(//a[@class = 'btn btn-small btn-primary'])[1]").click()
# 输入”商品分类测试“
driver.find_element_by_id("class_name").send_keys(goodsClassName)
# 清空分类排序
driver.find_element_by_id("class_sort").clear()
# 输入新的排序
driver.find_element_by_id("class_sort").send_keys("1")
# 点击保存
driver.find_element_by_xpath("//button").click()
time.sleep(2)
# 点击后面的分类编辑
driver.find_element_by_xpath("//td[contains(.,'%s')]/following-sibling::td[4]/a[2]"%goodsClassName).click()
# 清空
driver.find_element_by_id("class_sort").clear()
# 重新输入4
driver.find_element_by_id("class_sort").send_keys("4")
# 点击保存
driver.find_element_by_xpath("(//button)[2]").click()
time.sleep(2)
# 得到最新商品分类测试的分类排序的值
actual=driver.find_element_by_xpath("//td[contains(.,'%s')]/following-sibling::td[2]/input"%(goodsClassName)).get_property("value")
# 断言
if actual == "4":
    writeLog("%s 测试通过" % (testCase))
else:
    writeLog("%s 测试失败" % (testCase))
    getPhoto(driver)
driver.quit()
